package cn.bravolinks.tools.controller;

import cn.bravolinks.tools.domain.Task;
import cn.bravolinks.tools.domain.User;
import cn.bravolinks.tools.service.TaskService;
import cn.bravolinks.tools.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 登陆成功以后跳转到汇总页面
 * @author ssy
 * 2017-06-10
 */
@Controller
@RequestMapping("overView")
public class OverViewController extends BaseController{

    @Autowired
    private TaskService taskService;
    @Autowired
    private UserService userService;
    @RequestMapping("/")
    public String userPage(){
        return "HomePage";
    }
    /**
     * 根据月份获取所有人员的任务
     * @param month 月份
     * @param year 年份
     * @return
     */
    @RequestMapping(value = "getTasksByMonth")
    @ResponseBody
    public Map<String,Object> getTasksByMonth(Integer month,Integer year){
    	Map<String,Object> resultMap=new HashMap<>();
    	List<User> resultUserList = userService.queryUser();
    	List<Task> resulttaskList=taskService.getAllByMonth(month,year);
    	for (Task task : resulttaskList) {
		if(task.getIsEnd()==1){
			System.out.println(task.getUserid()+"-"+"-"+task.getId()+"-"+task.getName());
		}
		}
    	resultMap.put("userList", resultUserList);
    	resultMap.put("taskList", resulttaskList);
        return resultMap;
    }
}
